﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Website.BoardWebControl
{
    public class TileImageButton : ImageButton
    {
        public int col, row;
        public frag_boardgame.Square sqr;

        public TileImageButton(frag_boardgame.Square sqr, int size)
        {
            this.sqr = sqr;
            col = sqr.Column;
            row = sqr.Row;
            if (sqr.player != null)
            {
                this.ToolTip = sqr.player.Name;
            }
            else
            {
                this.ToolTip = "Click to move here";
            }
            initGraphics(size);

        }

        public void initGraphics(int size)
        {

            this.Width = size;
            this.Height = size;

            if ((col + row) % 2 == 1)
            {
                this.ImageUrl = @"BoardWebControl/Graphics/tile_asphalt_1.bmp";
                this.Style.Add(@"background-image", @"url('BoardWebControl/Graphics/tile_asphalt_1.bmp')");

            }
            else
            {
                this.ImageUrl = @"BoardWebControl/Graphics/tile_asphalt_0.bmp";
                this.Style.Add(@"background-image", @"url('BoardWebControl/Graphics/tile_asphalt_0.bmp')");

            }


            if (sqr.player != null)
            {
                string color = "blue";
                int id = sqr.player.ID;
                switch (id)
                {
                    case 1: color = "blue";
                        break;
                    case 2: color = "red";
                        break;
                    case 3: color = "green";
                        break;
                    case 4: color = "purp";
                        break;
                    case 5: color = "blond";
                        break;
                    case 6: color = "gray";
                        break;
                    case 7: color = "orange";
                        break;

                    default: color = "brown";
                        break;

                }
                this.Attributes.Add("hasPlayer", 1.ToString());
                this.Attributes.Add("playerName", sqr.player.Name);
                this.Attributes.Add("playerHlt", sqr.player.Health.ToString());
                this.Attributes.Add("playerAcc", sqr.player.Accuracy.ToString());
                this.Attributes.Add("playerSpd", sqr.player.Speed.ToString());

                string imgUrl = @"BoardWebControl/Graphics/soldier_" + color + ".gif";
                this.ImageUrl = imgUrl;

            }

        }

    
    }
}
